package com.ssy.lingxi.enhance.serviceimpl.supplier;

import com.querydsl.core.BooleanBuilder;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.enhance.constant.PNOOuterStatusEnum;
import com.ssy.lingxi.enhance.constant.PNOSupplierInnerStatusEnum;
import com.ssy.lingxi.enhance.entity.QProduceNoticeOrderDO;
import com.ssy.lingxi.enhance.handler.jpa.QueryDslUtil;
import com.ssy.lingxi.enhance.model.qo.ProduceNoticeOrderQO;
import com.ssy.lingxi.enhance.model.vo.OuterAndInnerVO;
import com.ssy.lingxi.enhance.model.vo.ProduceNoticeOrderListVO;
import com.ssy.lingxi.enhance.service.supplier.SupplierAllService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 加工能力 - 指派生产通知单(供应商) - 生产通知单查询 - 业务实现层
 * @author fhj
 * @date 2020/10/20
 * @version 2.0.0
 */
@Slf4j
@Service
public class SupplierAllServiceImpl implements SupplierAllService {

    @Resource
    private QueryDslUtil queryDslUtil;

    /**
     * 外部状态/内部状态
     * */
    @Override
    public Wrapper<OuterAndInnerVO> outerAndInner() {
        OuterAndInnerVO vo = new OuterAndInnerVO();
        vo.setOuterList(PNOOuterStatusEnum.getAll());
        vo.setInnerList(PNOSupplierInnerStatusEnum.getAll());
        return Wrapper.success(vo);
    }

    /**
     * 列表
     * */
    @Override
    public Wrapper<PageData<ProduceNoticeOrderListVO>> list(ProduceNoticeOrderQO qo, UserLoginCacheDTO user) {
        //查询表实体 - 生产通知单
        QProduceNoticeOrderDO pno = QProduceNoticeOrderDO.produceNoticeOrderDO;

        //查询条件构造 - 必要条件
        BooleanBuilder predicates = new BooleanBuilder();
        predicates.and(pno.supplierMemberId.eq(user.getMemberId()));
        predicates.and(pno.supplierRoleId.eq(user.getMemberRoleId()));

        return Wrapper.success(queryDslUtil.getSupplierPNOList(qo, pno, predicates));
    }
}
